﻿$(function () {
    $("#divWelcome,#divGame").toggleClass("hidden");
    //$("#spnTimer").autoTimer({ text: "游戏运行时间:  <%= (time>=60?Math.floor( time \60):0)+'分' %><%= time %60 %>秒", interval: 1000 });
    var username = $.auto.storage.get("SNAKENAME");

    $("#iptName").on("input", function () {
        username = $.trim($(this).val());
        if (username)
            $(this).siblings().removeClass("disabled");
        else
            $(this).siblings().addClass("disabled");
        $("#spnName").text(username);
    });
    username && $("#iptName").val(username).trigger("input");
    $("#btnLogin").click(function () {
        $("#divWelcome,#divGame").toggleClass("hidden");
        $("#spnTimer").autoTimer({ text: "游戏运行时间", interval: 1000 });
        $.auto.storage.set("SNAKENAME", username);
    });
    var canvas = $("#canGame");
    var game = new SnakeModule.Game("shen",canvas)
    function render() {
        game.run();
        requestAnimationFrame(render)
    }
    render();
   
    //变色
    $("#btnChangecolor").click(function () {
        game.playerChangeColor();
    });
 
    

});

